package com.gzhu.knowledgeAdmin.controller;

import com.gzhu.knowledgeAdmin.common.result.R;
import com.gzhu.knowledgeAdmin.common.vo.PageVo;
import com.gzhu.knowledgeAdmin.service.XtyhscService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author laoba
 * @create 2023-04-30 17:42
 */
@RestController
@RequestMapping("knowledgeAdmin/xtyhsc")
@CrossOrigin
public class XtyhscController {

    @Autowired
    private XtyhscService xtyhscService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('collection.list')")
    public R list(@RequestParam Map<String, Object> params) {
        PageVo page = xtyhscService.queryPage(params);
        return R.ok(page);
    }
    /**
     * 收藏知识
     * @param id 知识id
     * @return
     */
    @PostMapping("/addCollection/{id}")
    @PreAuthorize("hasAuthority('knowledge.collection')")
    public R addCollection(@PathVariable("id")Integer id){
        xtyhscService.addCollection(id);
        return R.ok();
    }

    /**
     * 删除收藏
     * @param ids
     * @return
     */
    @DeleteMapping("/removeCollection")
    @PreAuthorize("hasAuthority('collection.delete')")
    public R removeCollection(@RequestBody List<String> ids){
        xtyhscService.removeByIds(ids);
        return R.ok();
    }
}
